﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;

public partial class videoroom : System.Web.UI.Page
{
    public string xgsp = "";    //相关视频
    public DataRow Dqsp = null;    //当前视频

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            xgsp = Xgsp().ToString();
            Dqsp = VideoBll.GetVideoById(Id);
        }
    }
    /// <summary>
    /// 接收的视频编号
    /// </summary>
    private int Id
    {
        get
        {
            int id = 0; 
            try
            {
                id = int.Parse(Request.QueryString["id"]);
            }
            catch
            {
                Response.Write("<script>alert('您输入的Id不正确');window.close();</script>");
                Response.End();
            }
            return id;
        }
    }
    private Web_VedioBLL videoBll;
    /// <summary>
    /// 视频业务类
    /// </summary>
    private Web_VedioBLL VideoBll
    {
        get
        {
            if (videoBll == null)
            {
                videoBll = new Web_VedioBLL();
            }
            return videoBll;
        }
    }

    private NewsDetailBLL newsDetailsBLL;
    /// <summary>
    /// 
    /// </summary>
    private NewsDetailBLL NewsDetailsBLL
    {
        get
        {
            if (newsDetailsBLL == null)
            {
                newsDetailsBLL = new NewsDetailBLL();
            }
            return newsDetailsBLL;
        }
    }

    /// <summary>
    /// 相关视频
    /// </summary>
    /// <returns></returns>
    public StringBuilder Xgsp()
    {
        StringBuilder sbSgxp = new StringBuilder();
        

        DataTable dt = VideoBll.GetVideoRelated(Id);
        if (dt != null)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                System.Data.DataRow row = dt.Rows[i];
                int v_id = Convert.ToInt32(row["v_id"].ToString());
                string title = Convert.ToString(row["v_title"]);
                string url = Convert.ToString(row["v_url"]);
                string teacher = Convert.ToString(row["setup_user"]);
                string sum = Convert.ToString(row["v_remark"]);
                DateTime date = Convert.ToDateTime(row["setup_date"]);
                url = url.Substring(0, url.IndexOf("$"));

                //视频图片显示
                DataRow row1 = VideoBll.GetVideoById(v_id);
                int classid = Tools.GetInt(row1["classid"]).Value;
                Web_video_imgDAL dal = new Web_video_imgDAL();
                Web_video_img img = dal.GetElementById(v_id, classid);

                if (img != null)
                    sbSgxp.AppendLine("<li><div class=\"video_line\"><a href='#' date=\"" + date + "\" sum=\"" + sum + "\" teacher=\"" + teacher + "\" title=\"" + title + "\" t=\"a\" url=\"" + url + "\"><img src=\"uploadimages/" + img.V_img + "\" style=\"display:block;cursor:pointer;\" width=\"158\" height=\"118\" border=\"0\"/></a></div>");
                else
                    sbSgxp.AppendLine("<li><div class=\"video_line\"><a href='#' date=\"" + date + "\" sum=\"" + sum + "\" teacher=\"" + teacher + "\" title=\"" + title + "\" t=\"a\" url=\"" + url + "\"><img src=\"uploadimages/pig1.jpg\" style=\"display:block;cursor:pointer;\" width=\"158\" height=\"118\" border=\"0\"/></a></div>");

                sbSgxp.AppendLine(string.Format("<a href='{0}' target=\"_blank\" url='{1}'>{2}</a></li>", url, url, title.Length > 10 ? title.Substring(0, 10) + "..." : title));
                if (i == 7)
                {
                    break;
                }
            }
        }
        return sbSgxp;
    }

}